import { BaseModel, ModelAttributes, WhereCondition, OrderBy, PaginationOptions } from './BaseModel';

export interface UserAttributes {
  id?: number;
  openid: string;
  nickname?: string;
  avatar_url?: string;
  profile?: string;
  last_login_at?: Date;
  is_active?: boolean;
  created_at?: Date;
  updated_at?: Date;
}

export class User extends BaseModel {
  constructor() {
    super('user');
  }

  
  /**
   * 根据openid查找用户
   * @param openid 用户openid
   */
  async findUserByOpenid(openid: string): Promise<UserAttributes | null> {
    return await this.findOne({ openid });
  }

  /**
   * 更新用户最后登录时间
   * @param id 用户ID
   */
  async updateLastLoginTime(id: number): Promise<UserAttributes | null> {
    return await this.updateById(id, { last_login_at: new Date() });
  }
}